//
//  LGKNoteBaseViewController.m
//  LGKNote
//
//  Created by 刘亚军 on 2023/5/26.
//

#import "LGKNoteBaseViewController.h"
#import "LGKConst.h"
@interface LGKNoteBaseViewController ()
@property (nonatomic,strong) UIButton *backBtn;
@property (nonatomic,strong) MarqueeLabel *marqueeTitleLabel;
@end

@implementation LGKNoteBaseViewController

- (instancetype)init{
    if (self = [super init]) {
        [self configure];
    }
    return self;
}
- (instancetype)initWithDataModelName:(NSString *)dataModelName{
    if (self = [super initWithDataModelName:dataModelName]) {
        [self configure];
    }
    return self;
}
- (void)configure{
    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:self.navigationItem.backBarButtonItem.style target:nil action:nil];
    self.navigationController.navigationBar.translucent = NO;
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.marqueeTitle = @"";
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:self.backBtn];
    self.navigationItem.titleView = self.marqueeTitleLabel;
}
- (void)setTitle:(NSString *)title{
    [super setTitle:title];
    self.marqueeTitleLabel.text = title;
}
- (void)setMarqueeTitle:(NSString *)marqueeTitle{
    _marqueeTitle = marqueeTitle;
    self.marqueeTitleLabel.text = marqueeTitle;
}
- (void)navBar_leftItemPressed:(UIBarButtonItem *)sender{
    [self.navigationController popViewControllerAnimated:YES];
}
- (MarqueeLabel *)marqueeTitleLabel {
    if (!_marqueeTitleLabel) {
        _marqueeTitleLabel = [[MarqueeLabel alloc] initWithFrame:CGRectMake(0, 0,LG_ScreenWidth-180, 28) rate:10 andFadeLength:5];
        _marqueeTitleLabel.animationDelay = 2.0;
        _marqueeTitleLabel.font = [UIFont systemFontOfSize:IsIPad ? 20 : 18 weight:UIFontWeightMedium];
        _marqueeTitleLabel.textColor = [UIColor whiteColor];
        _marqueeTitleLabel.textAlignment = NSTextAlignmentCenter;
        _marqueeTitleLabel.trailingBuffer = 24;
        _marqueeTitleLabel.marqueeType = MLContinuous;
    }
    return _marqueeTitleLabel;
}
- (UIButton *)backBtn{
    if (!_backBtn) {
        _backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _backBtn.frame = CGRectMake(0, 0, 40, 28);
        [_backBtn setImageEdgeInsets: UIEdgeInsetsMake(0, -32, 0, 0)];
        [_backBtn setImage:[UIImage yj_imageNamed:@"lg_navigationBar_back" atBundle:LGKNoteManager.defaultManager.noteBundle] forState:UIControlStateNormal];
        [_backBtn addTarget:self action:@selector(navBar_leftItemPressed:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _backBtn;
}
@end
